This notebook takes a logfile generated from the linux candump tool along with a DBC file to produce charts of signals.
# @hidden_cell
dbcfile_path = "PER_2021.dbc"
logfile_path = ".\\logs\\apps_on_all_state_transitions.txt"
print(f"Using DBC '{dbcfile_path}', Logfile '{logfile_path}'.")
Using DBC 'PER_2021.dbc', Logfile '.\logs\apps_on_all_state_transitions.txt'.
# @hidden_cell
from ipywidgets import interact
# Bokeh plotting
from bokeh.io import push_notebook, output_notebook, show
from bokeh.models import ColumnDataSource, HoverTool
from bokeh.plotting import figure
from bokeh.palettes import Dark2_5 as palette
from bokeh.layouts import gridplot
output_notebook()
import itertools
# Pandas plotting with plotly
import pandas as pd
# Data Processing
import cantools
from parse_candump import candump_to_series
# @hidden_cell
# Plots are originized by rows and columns of 2
plot_layout = [
["Throttle_Position_A", "Throttle_Position_B"],
["Brake_Position_A", "Brake_Position_B"],
["EMDRIVE_TorqueActual"],
["EMDRIVE_CurrentDemand"],
["EMDRIVE_StatusWord"],
["Car_State", "Precharge_State"],
["EMDRIVE_DCLinkVoltage"],
["EMDRIVE_MotorTemp", "EMDRIVE_ControllerTemp"],
]
# Create a list of all plots based on the layout descrived by plot_layout
def create_plots(all_signals):
if not all_signals: return None
all_df = pd.DataFrame(all_signals)
all_df.index = all_df.index.astype(float)
fill_df = all_df.fillna(method="ffill")
all_plots = []
colors = itertools.cycle(palette)
glob_x_range = None
for signal_group in plot_layout:
p = figure(sizing_mode="scale_width", plot_height=500, x_range=glob_x_range)
if len(all_plots) == 0:
# Sync all figure's x_range so they move together
glob_x_range = p.x_range
for signal_name, color in zip(signal_group, colors):
p.line(
x=fill_df[signal_name].index,
y=fill_df[signal_name],
legend_label=signal_name,
color=color
)
p.legend.location = "top_left"
p.legend.click_policy="hide"
all_plots.append(p)
return all_plots
# @hidden_cell
# Plot!
all_signals = candump_to_series(dbcfile_path, logfile_path)
print(f"Was able to parse the following signals: {all_signals.keys()}")
p = gridplot(create_plots(all_signals), ncols=2)
show(p)
Error parsing message with ID 0x350 from DBC file. Error parsing message with ID 0x350 from DBC file.